package org.ethereum.cli;

import java.io.File;
import java.io.FileWriter;
import java.io.Writer;
import java.util.Properties;

import org.ethereum.crypto.ECKey;
import org.spongycastle.util.encoders.Hex;

public class GenNodeKeyStore {

	public static void main(String[] args) {
		File file = new File(".", "nodeId.properties");
		Properties props = new Properties();
		ECKey key = new ECKey();
		props.setProperty("nodeIdPrivateKey", Hex.toHexString(key.getPrivKeyBytes()));
		props.setProperty("nodeId", Hex.toHexString(key.getNodeId()));
		file.getParentFile().mkdirs();
		try {
			try (Writer w = new FileWriter(file)) {
				props.store(w,
						"Generated NodeID. To use your own nodeId please refer to 'peer.privateKey' config option.");
			}
		} catch (Exception e) {
			e.printStackTrace(System.err);
		}
		System.out.println("New nodeID generated: " + props.getProperty("nodeId"));
		System.out.println("Generated nodeID and its private key stored in " + file);
		
		File file1 = new File(".", "version.properties");
		Properties props1 = new Properties();
		props1.setProperty("databaseVersion", "5");
		try {
			try (Writer w = new FileWriter(file1)) {
				props1.store(w, "Generated database version.");
			}
		} catch (Exception e) {
			e.printStackTrace(System.err);
		}
	}

}
